package com.sdi.columbus;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class GetReportDetails extends Activity{
  Intent news,newss;
  Bundle bun,forrep;
  String stime,etime,responses,reports,runningtime,duration,accountID;
  int MaxSpeed,MinSpeed,distance;
  String VehicleId;
  private static Double green;
  GetReport get;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		news=getIntent();
		bun=news.getExtras();
		VehicleId=bun.getString("vehicleids");
		stime=bun.getString("start");
		etime=bun.getString("end");
		accountID=ColombusApp.getSharedApp().accountId;
		
		    get=new GetReport();
    	
			try {
				responses=get.GetValues(accountID,VehicleId,stime,etime);
				JSONObject json = new JSONObject(responses);
				reports= json.getString("GetTripSummaryResult");				
				System.out.println("first report"+reports);
				
				JSONObject json1 = new JSONObject(reports);
				
				
				MaxSpeed=Integer.parseInt(json1.getString("MaximumSpeed"));
				MinSpeed=Integer.parseInt(json1.getString("MinimumSpeed"));
				runningtime=json1.getString("TotalRunningTime");
				distance=Integer.parseInt(json1.getString("TotalDistance"));
				green=Double.parseDouble(json1.getString("GreenDriveIndex"));
				duration=json1.getString("TotalDuration");
				
				
				if(MaxSpeed==0 && MinSpeed==0 && distance==0)
		        {
		        	System.out.println("enters if check");
		        	//Toast.makeText(getBaseContext(), "Sorry No GPS data is available for the vehicle for the time period", Toast.LENGTH_LONG).show();
		        	Intent p=new Intent(GetReportDetails.this,MapData.class);
		        	startActivity(p);
		        }	
				else
				{
					news=new Intent(GetReportDetails.this,DisplayReport.class);
					forrep=new Bundle();
//					forrep.putInt("vehicleids", VehicleId);
					forrep.putString("accountID", accountID);
					forrep.putString("vehicleids", VehicleId);
					forrep.putString("start", stime);
					forrep.putString("end",etime);
					
					news.putExtras(forrep);
					startActivity(news);
					
				}
				
				
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
			
	}
	

}
